﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.ServiceModel;
using FCS.Communication;
using System.ServiceModel.Description;

namespace FCS.Communication.Host
{
    public partial class WCFService : ServiceBase
    {
        ServiceHost host;
        EventLogWriter _logger = new EventLogWriter("WCF Service");

        public WCFService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            try
            {
                // We want to instantiate a service of type CPQ 
                Type serviceType = typeof(CommandPriorityQueue);
               // Create the service host and open it for use
                host = new ServiceHost(serviceType);
                host.Open();

                _logger.WriteToLog(EventLogEntryType.Information, "Starting server");
            }
            catch (Exception ex)
            {
                _logger.WriteToLog(EventLogEntryType.Error, ex.Message);
            }
        }

        protected override void OnStop()
        {
            if (host != null)
            {
                host.Close();
            }
        }
    }
}
